package com.wish.group05.house.controller;

import java.util.HashMap;
import java.util.List;
import javax.annotation.Resource;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.wish.group05.base.entity.BusinessCircle;
import com.wish.group05.base.entity.PremisesInfo;
import com.wish.group05.base.entity.Subway;
import com.wish.group05.base.entity.SysRegion;
import com.wish.group05.base.service.*;
import com.wish.group05.common.core.utils.StringUtils;
import com.wish.group05.system.api.RemoteDictDataService;
import com.wish.group05.system.api.RemoteSmsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.wish.group05.common.log.annotation.Log;
import com.wish.group05.common.log.enums.BusinessType;
import com.wish.group05.common.security.annotation.PreAuthorize;
import com.wish.group05.common.core.web.controller.BaseController;
import com.wish.group05.common.core.web.domain.AjaxResult;
import com.wish.group05.common.core.web.page.TableDataInfo;

/**
 * 楼盘信息Controller
 * 楼盘信息提交git 测试
 * @author wish
 * @date 2022-05-24
 */
@RestController
@RequestMapping("/info")
public class TbPremisesInfoController extends BaseController
{
    @Autowired
    private IPremisesInfoService premisesInfoService;
    @Autowired
    ISysRegionService sysRegionService;
    @Autowired
    ISubwayService subwayService;
    @Autowired
    IBusinessCircleService businessCircleService;
    @Autowired
    IConfigPremisesPropertyService premisesPropertyService;
    @Resource
    RemoteDictDataService remoteDictDataService;

    @GetMapping("ByIdPremisesInfo/{id}")
    public AjaxResult ByIdPremisesInfo(@PathVariable(value = "id")Integer id){
        PremisesInfo a = premisesInfoService.ByIdPremisesInfo(id);
        return AjaxResult.success(a);
    }

    @GetMapping("/communityType")
    public AjaxResult communityType(PremisesInfo premisesInfo){
        HashMap<String, Object> map = new HashMap<>();
        if (premisesInfo.getId()==1){
            AjaxResult sysCommunityType = remoteDictDataService.getDictDataList("sys_community_type");
            map.put("communityTypeList",sysCommunityType);
        }
        if (premisesInfo.getId()==2){
            AjaxResult sysBuildingType = remoteDictDataService.getDictDataList("sys_building_type");
            map.put("buildingTypeList",sysBuildingType);
        }
        if (premisesInfo.getId()==3){
            AjaxResult sysPremisesType = remoteDictDataService.getDictDataList("sys_premises_type");
            map.put("premisesTypeList",sysPremisesType);
        }
        return AjaxResult.success(map);
    }


    /**
     * 楼盘列表
     */
    @GetMapping("/RemarkList")
    public AjaxResult RemarkList(){
        return AjaxResult.success(premisesPropertyService.list());
    }

    /**
     * 商圈查询
     */
    @GetMapping("/ShangQuanList")
    public AjaxResult ShangQuanList(PremisesInfo premisesInfo){
        return AjaxResult.success(businessCircleService.list(new QueryWrapper<BusinessCircle>()
                .eq("code",premisesInfo.getCounty())));
    }

    /**
     * 地铁查询
     */
    @GetMapping("/subwayList")
    public AjaxResult subwayList(Subway sysRegion){
        return AjaxResult.success(subwayService.list(new QueryWrapper<Subway>()
                .eq("city",sysRegion.getCity())));
    }

    /**
     * 三级联动查询
     */
    @GetMapping("/shengList")
    public AjaxResult shengList(SysRegion sysRegion){
        return AjaxResult.success(sysRegionService.list(new QueryWrapper<SysRegion>()
                .eq("parent_id",sysRegion.getParentId())));
    }

    /**
     * 查询楼盘信息列表
     */
    @PreAuthorize(hasPermi = "house:info:list")
    @GetMapping("/list")
    public TableDataInfo list(PremisesInfo premisesInfo)
    {
        QueryWrapper<PremisesInfo> queryWrapper = new QueryWrapper<>();

        startPage();
        //判断为空
        if(!StringUtils.isEmpty(premisesInfo.getName())){
            queryWrapper.like("name",premisesInfo.getName());
        }
        List<PremisesInfo> list = premisesInfoService.list(queryWrapper);
        return getDataTable(list);
    }

//    /**
//     * 导出楼盘信息列表
//     */
//    @PreAuthorize(hasPermi = "system:info:export")
//    @Log(title = "楼盘信息", businessType = BusinessType.EXPORT)
//    @PostMapping("/export")
//    public void export(HttpServletResponse response, TbPremisesInfo tbPremisesInfo) throws IOException
//    {
//        List<TbPremisesInfo> list = tbPremisesInfoService.selectTbPremisesInfoList(tbPremisesInfo);
//        ExcelUtil<TbPremisesInfo> util = new ExcelUtil<TbPremisesInfo>(TbPremisesInfo.class);
//        util.exportExcel(response, list, "info");
//    }
//
//    /**
//     * 获取楼盘信息详细信息
//     */
//    @PreAuthorize(hasPermi = "system:info:query")
//    @GetMapping(value = "/{id}")
//    public AjaxResult getInfo(@PathVariable("id") Long id)
//    {
//        return AjaxResult.success(tbPremisesInfoService.selectTbPremisesInfoById(id));
//    }
//
    /**
     * 新增楼盘信息
     */

    @PreAuthorize(hasPermi = "system:info:add")
    @Log(title = "楼盘信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PremisesInfo tbPremisesInfo)
    {
        boolean flag = premisesInfoService.addtbPremisesInfo(tbPremisesInfo);
        return toAjax(flag==true?1:0);
    }
//
//    /**
//     * 修改楼盘信息
//     */
//    @PreAuthorize(hasPermi = "system:info:edit")
//    @Log(title = "楼盘信息", businessType = BusinessType.UPDATE)
//    @PutMapping
//    public AjaxResult edit(@RequestBody TbPremisesInfo tbPremisesInfo)
//    {
//        return toAjax(tbPremisesInfoService.updateTbPremisesInfo(tbPremisesInfo));
//    }
//
//    /**
//     * 删除楼盘信息
//     */
//    @PreAuthorize(hasPermi = "system:info:remove")
//    @Log(title = "楼盘信息", businessType = BusinessType.DELETE)
//	@DeleteMapping("/{ids}")
//    public AjaxResult remove(@PathVariable Long[] ids)
//    {
//        return toAjax(tbPremisesInfoService.deleteTbPremisesInfoByIds(ids));
//    }
}
